//
//  JHAddContactViewController.m
//  JHChat
//
//  Created by JiaHao on 2/22/15.
//  Copyright (c) 2015 JiaHao. All rights reserved.
//

#import "JHAddContactViewController.h"

@interface JHAddContactViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userNameTextField;
@property (strong, nonatomic) XMPPStream * xmppStream;
@property (strong,nonatomic) XMPPRoster *xmppRoster;
@end

@implementation JHAddContactViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.xmppRoster = [[JHXMPPManager sharedManager] xmppRoster];
    self.xmppStream = [[JHXMPPManager sharedManager] xmppStream];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)toAdd:(id)sender {
    
    XMPPJID *newBuddy = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@%@",self.userNameTextField.text,XMPP_HOST_NAME]];
    //[self.xmppRoster subscribePresenceToUser:newBuddy];
    [self.xmppRoster addUser:newBuddy withNickname:self.userNameTextField.text groups:@[@"Friends"] subscribeToPresence:YES];
    [UIAlertView showWithTitle:@"提示" message:@"已经发送好友请求" cancelButtonTitle:@"确定" otherButtonTitles:nil tapBlock:^(UIAlertView *alertView, NSInteger buttonIndex) {
        [self.navigationController popViewControllerAnimated:YES];
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
